function R = compute_residual_image_wiener(image, k, sz, segma)
if nargin < 2
    k = 1;
end
if nargin < 3
    sz = 3;
end
if nargin < 4
    segma = 1;
end
R = double(image);
G = fspecial('gaussian', [sz sz], segma);
for i = 1:k
    R = residual_image(R, G);
end
end

function R = residual_image(image, filt)
    p_m = round(imfilter(image, filt, 'same'));
    % after padding, edge values are distorted.
    R = image(2:end-1,2:end-1) - p_m(2:end-1,2:end-1);
end
